<?php
namespace Home\Controller;
use Think\Controller;
use Think\Model;
use Home\Model\ContentCollectModel;
class CollectController extends Controller {

    	
     //回答列表和报警查找,1问答，2，新闻
    public function collectList(){
    	if(session('name')){
    		$map = array();
    	if(!empty(I('param.key',''))){
    		$map['text_content'] = array('like','%'.I('param.key','').'%');
    	}
    	if(!empty(I('param.task_id',''))){
    		$map['task_id'] = I('param.task_id','');
    	}
    	if(!empty(I('param.id',''))){
    		$map['spider_content_collect.id'] = intval(I('param.id'));
    	}
    	$map['spider_content_collect.task_type'] = I('param.task_type',1);
    	$answerTable = D('ContentCollect');
    	$answerTable->mySelect(session('uid'));
    	//replace( replace('text_content','【','<span style='color:red'>【'),'】','】<span>') as mycontent
    	$answerTable->field(array("spider_content_collect.*",'spider_task.task_name'))->join('spider_task ON spider_task.id = spider_content_collect.task_id','LEFT')->relation(true)->where($map);
    	if(!empty(I('param.page','')) && !empty(I('param.pageCount',''))){
    		$answerTable->page(I('param.page'),I('param.pageCount'));
    	}
    	$answer = $answerTable->select();
    		echo json_encode(array('result'=>$answer,'count'=>$answerTable->where($map)->count(),'code'=>1));
    	}else{
    		echo json_encode(array('result'=>'登录失效重新登陆','code'=>0));
    	}
    }
    
    //修改问答已读状态
    public function updateRead(){
    	if(session('name')){
    		$isRead = I('param.isRead');
    		$userReadTable = M('UserRead');
    		if($isRead == 1){
    			$date['uid'] = session('uid');
    			$date['ccid'] = I('param.ccid','');
    			$userReadTable->add($date);
    		}else{
    			$map['uid'] = session('uid');
    			$map['ccid'] = I('param.ccid','');
    			$userReadTable->where($map)->delete();
    		}
    		echo json_encode(array('result'=>'修改成功','code'=>1));
    	}else{
    		echo json_encode(array('result'=>'登录失效重新登陆','code'=>0));
    	}
    }
    

}